package com.itsci.assignment2;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class Login extends Activity{
	private EditText user;
	private EditText pass;
	private LoginManager loginMgr;
	private LoginBean login;
	private Button btn;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.login);
		user = (EditText)findViewById(R.id.editText_login_username);
		pass = (EditText)findViewById(R.id.editText_login_password);
		btn = (Button)findViewById(R.id.button_login_submit);
		loginMgr = new LoginManager(Login.this, null, null, 1);
		btn.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				login = loginMgr.getByStudentId(user.getText().toString());
				String u = login.getUsername();
				String p = login.getPassword();
				if(u.equalsIgnoreCase(user.getText().toString())&&p.equalsIgnoreCase(pass.getText().toString())){
					Intent gotoMenu = new Intent(Login.this,ListMenu.class);
					gotoMenu.putExtra("user",user.getText().toString());
//					startActivityForResult(gotoMenu,111);
					startActivity(gotoMenu);
				}
				else{
					Intent gotoMain = new Intent(Login.this,MainActivity.class);
					startActivity(gotoMain);
				}
				
			}
		});

	}
	

}
